package com.ruihang.generalibrary.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.ruihang.generalibrary.R;
import com.ruihang.generalibrary.beans.ShareItem;
import com.ruihang.generalibrary.ui.adapter.holder.ShareHolder;

import java.util.List;


/**
 * Created by Ly on 2016/10/27.
 */
public class ShareGrideAdapter extends BaseAbstractAdapter<ShareItem> {

    public ShareGrideAdapter(Context context, List<ShareItem> datas) {
        super(context, datas);
    }

    public ShareGrideAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ShareHolder sh=null;
        if(view==null){
            view= LayoutInflater.from(context).inflate(R.layout.item_share, viewGroup, false);
            sh=new ShareHolder(view);
        }else{
            sh= (ShareHolder) view.getTag();
        }
        ShareItem si=datas.get(i);
        sh.img.setImageResource(si.getIconRes());
        if(TextUtils.isEmpty(si.getItemName())){
            if(si.getItemNameRes()==0){
                sh.itemName.setText("<未命名>");
            }else{
                sh.itemName.setText(si.getItemNameRes());
            }
        }
        return view;
    }
}
